<?php
/********************************************************
 *
 * 此文件的作用:
 *		所有文章的操作
 *
 * @copyright Copyright (c) 2007-12-20
 * @author 刘昌功 lcg635@126.com
 *
 ********************************************************/
defined('APP_DIR') or die('404 Not Found');

FLEA::loadClass('Common_Model');

class Model_News extends Common_Model {
	function __construct() {
		parent::Common_Model();
		$this->_tb = FLEA::getSingleton('Table_News');
	}


	function getList($type = 'index', $page = 0, $pageSize = 15, $pagerData = true) {
		FLEA::loadHelper('pager');
		$fields = 'title, important, author,created, news_id, type';
		$cond = null;
		
		switch ($type) {
			case 'index':$cond = 'type = 0';break;
			case 'jj':$cond = 'type = 1';break;
		}

		$pager = new FLEA_Helper_Pager($this->_tb, $page, $pageSize, $cond, 'created desc');
		$lists = $pager->findAll($fields);
		foreach ($lists as $k => $v)
			$lists[$k]['important'] = 1 == $v['important'] ? 'red' : '';

		$viewData['lists'] = $lists;
		if ( true == $pagerData )
			$viewData['pagerData'] = $pager->getPagerData();
		return $viewData;
	}

	function getInfo($nid) {
		$result = $this->_tb->find('news_id = ' . $nid);
		return $result;
	}

	function insert($row) {
		$resutl = $this->_tb->create($row);
		return $result;
	}

	function update($row) {
		$resutl = $this->_tb->update($row);
		return $result;
	}

	function delete($nid) {
		$resutl = $this->_tb->removeByPkv($nid);
		return $result;
	}

	function getForm($type, $data = null) {
		return $this->_tb->form($type, $data);
	}
}